<template>

<div id="index">
        <div class="scrollTop" v-show="showTop" @click="toTop">
    <img src="../../assets/huidaodingbu.svg" width="40px" height="40px"/>
 
  </div>
    <el-container>
  <el-header height="80px">
        <Top/>
      </el-header>
  <el-main>
    <Main/>
  </el-main>
  <el-footer>
    <Footer/>
  </el-footer>
</el-container>
</div>
</template>


<script>
import Top from '@/components/index/Top'
import Main from '@/components/index/Main'
import Footer from '@/components/index/footer'
export default {
    data() {
    return {
     scrollTop: 0,
        time: 0,
        dParams: 20,
        scrollState: 0
    };
  },
  components: {
    Top,
    Main,
    Footer,
    showTop: function(){
        let value = this.scrollTop>200?true:false;
        return value;
      },
  },
   mounted() {
      window.addEventListener('scroll', this.getScrollTop);
    },
      methods: {
      toTop(e) {
        if(!!this.scrollState){
          return;
        }
        this.scrollState = 1;
        e.preventDefault();
        let distance = document.documentElement.scrollTop || document.body.scrollTop;
        let _this = this;
        this.time = setInterval(function(){ _this.gotoTop(_this.scrollTop-_this.dParams) }, 10);
      },
      gotoTop(distance){
        this.dParams += 20;
        distance = distance>0 ? distance : 0;
        document.documentElement.scrollTop = document.body.scrollTop = window.pageYOffset = distance;
        if(this.scrollTop < 10){
          clearInterval(this.time);
          this.dParams = 20;
          this.scrollState = 0;
        }
      },
      getScrollTop() {
        this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      }
    },
}
</script>
<style scoped>
 .scrollTop {
    position: fixed;
    right: 40px;
    bottom: 80px;
    cursor: pointer;
  }
.el-header {
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 80px;
  font-family: "STXingkai";
  font-size: 30px;
  position: relative;
  right: 150px;
}

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }
  .el-footer {
    /* background-color: #B3C0D1; */
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  /*  */
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
</style>

